﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNLTHD_GoogleMapAPI_DTO;
using CNLTHD_GoogleMapAPI_DAO;

namespace CNLTHD_GoogleMapAPI
{
	public partial class ToaDoGanNhat : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{

			string sMaLoaiDiaDiem = Request.QueryString["MaLoaiDiaDiem"];
			string kinhDo = Request.QueryString["KinhDo"];
			string viDo = Request.QueryString["ViDo"];
			if (sMaLoaiDiaDiem == null || kinhDo == null || viDo == null)
			{
				return;
			}
			LoaiDiaDiem ldd = new LoaiDiaDiem { MaLoaiDiaDiem = int.Parse(sMaLoaiDiaDiem) };

			List<DiaDiem> ds = DiaDiemDAO.LayDanhSachDiaDiem(ldd);

			DiaDiem dd = TinhDiaDiemGanNhat(ds, double.Parse(kinhDo), double.Parse(viDo));

			string text = "Tọa độ của bạn là: Kinh độ:"+ kinhDo+", Vĩ độ"+ viDo;
			Response.Redirect("~/MyMap.aspx?TenDiaDiem=" + dd.TenDiaDiem +"&MaDiaDiem="+dd.MaDiaDiem.ToString() +"&text="+text);


		}

		private DiaDiem TinhDiaDiemGanNhat(List<DiaDiem> ds, double p, double p_2)
		{
			return ds.FirstOrDefault();
		}
	}
}